package com.yzw.course.controller;

import com.yzw.common.domain.EduVideo;
import com.yzw.common.dto.R;
import com.yzw.course.service.EduVideoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author Yzw
 * @Description TODO
 * @Date 2023/5/12 17:00
 * @Version 1.0
 */
@RequestMapping("/video")
@RestController
public class EduVideoController {
    @Resource
    private EduVideoService eduVideoService;

    // 添加小节
    @ApiOperation("添加小节")
    @PostMapping()
    public R saveVideo(@RequestBody EduVideo eduVideo) {
        eduVideoService.save(eduVideo);
        return R.success("添加小节成功", null);
    }

    // 根据小节id查询小节信息
    @ApiOperation("根据小节id查询小节信息")
    @GetMapping("/getAllVideo/{videoId}")
    public R getAllVideo(@PathVariable String videoId) {
        EduVideo eduVideo = eduVideoService.getById(videoId);
        return R.success("查询成功", eduVideo);
    }


    // 修改小节
    @ApiOperation("修改小节")
    @PutMapping()
    public R updVideo(@RequestBody EduVideo eduVideo) {
        eduVideoService.updateById(eduVideo);
        return R.success("修改小节成功", null);
    }

    // 删除小节
    @ApiOperation("删除小节")
    @DeleteMapping("{videoId}")
    public R delVideo(@PathVariable String videoId) {
        eduVideoService.removeById(videoId);
        return R.success("删除小节成功", null);
    }
}
